//
//  HGNormalCollectionViewCell.m
//  悦享
//
//  Created by dllo on 16/3/19.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HGNormalCollectionViewCell.h"
#import "HGSubNormalCollectionViewCell.h"
@interface HGNormalCollectionViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collection;

@end

@implementation HGNormalCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollection];
    }
    return self;
}

- (void)setArr:(NSMutableArray *)arr{
    _arr = arr;
    [_collection reloadData];
}


- (void)createCollection{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(5, 10, 10, 10);
    layout.itemSize = CGSizeMake((SREEN_WIDTH - 30)/2, 150);
    
    
    self.collection = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_collection];
    
    [_collection registerClass:[HGSubNormalCollectionViewCell class] forCellWithReuseIdentifier:@"HGSubNormalCollectionViewCell"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HGSubNormalCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HGSubNormalCollectionViewCell" forIndexPath:indexPath];
    
    TVModel *model = _arr[indexPath.row];
    
    cell.model = model;

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    TVModel *model = _arr[indexPath.row];
    
    [self.delegate jumpToVcWithUrl:model.playUrl];
    
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
}

@end
